package com.egao.appo.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
//import com.egao.appo.mapper.MessageMapper;
import com.egao.appo.entity.Message;
import com.egao.appo.service.MessageService;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import com.egao.appo.biz.MessageBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 消息服务实现类
 * @author : Doman
 * @date : 2021-08-25 16:22:48
 * @version ：1.0
 */
@Service
public class MessageServiceImpl /*extends ServiceImpl<MessageMapper, Message> */implements MessageService {

	@Autowired
	private MessageBiz messageBiz;

    /**
    @Override
    public PageResult<Message> listPage(PageParam<Message> page) {
        List<Message> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<Message> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, Message message, User loginUser)  throws Exception{
        return messageBiz.list(page,message,loginUser);
    }

    @Override
    public JsonResult list(Message message, User loginUser) {
        return JsonResult.ok().setData(messageBiz.list(message,loginUser));
    }

    @Override
    public JsonResult examinedMessage(Message message) {
        try {
            return JsonResult.ok().setData(messageBiz.examinedMessage(message));
        } catch (EmptyResultDataAccessException e) {
            return JsonResult.ok();
        }
    }

    @Override
    public JsonResult getById(Message message) {
        return JsonResult.ok().setData(messageBiz.getById(message));
    }

    @Transactional
    @Override
    public JsonResult save(Message message, User loginUser) {
        if (messageBiz.save(message, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(Message message, User loginUser) {
        if (messageBiz.update(message, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(Message message, User loginUser) {
        if (messageBiz.remove(message, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
